package com.example.server.service.implement;

import com.example.server.entity.RecentPlayedScript;
import com.example.server.entity.Role;
import com.example.server.entity.Scene;
import com.example.server.entity.Script;
import com.example.server.mapper.ScriptMapper;
import com.example.server.service.ScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScriptServiceImpl implements ScriptService {

    @Autowired
    private ScriptMapper scriptMapper;

    @Override
    public Script addScript(String title, String author,String image, String content, String tags) {
        scriptMapper.insertScript(title,author,content,tags);
        Script s=scriptMapper.selectScriptByTitle(title);
        scriptMapper.uploadScriptImage(s.getId(),image);
        // System.out.println(s);
        return s;
    }

    @Override
    public Script getScriptById(Integer id) {
        return scriptMapper.selectScriptById(id);
    }

    @Override
    public List<Script> getAllScripts() {
        return scriptMapper.selectAllScripts();
    }

    @Override
    public List<Script> getScriptsByTitle(String title) {
        return scriptMapper.selectScriptsByTitle(title);
    }

    @Override
    public List<RecentPlayedScript> getRecentPlayedScripts(Integer id) {
        return scriptMapper.selectRecentPlayed(id);
    }

    @Override
    public void updateScript(Integer id, String title, String content, String tags) {
        scriptMapper.updateScript(id, title, content, tags);
    }

    @Override
    public List<Script> getScriptsByAuthor(String author) {
        return scriptMapper.selectScriptsByAuthor(author);
    }

    @Override
    public void deleteScriptByID(Integer id) {
        scriptMapper.deleteScriptById(id);
    }

    @Override
    public void addRole(Integer scriptId, String name, String description, String traits) {
        scriptMapper.insertRole(scriptId, name, description, traits);
    }

    @Override
    public void addScene(Integer scriptId, String description) {
        System.out.println(scriptId+description);
        scriptMapper.insertScene(scriptId, description);
    }

    @Override
    public void updateRole(Integer id, Integer scriptId, String name, String description, String traits) {
        scriptMapper.updateRole(id, scriptId, name, description, traits);
    }

    @Override
    public void updateScene(Integer id, String sceneDescription) {
        System.out.println(id+sceneDescription);
        scriptMapper.updateScene(id,  sceneDescription);
        System.out.println("end");
    }

    @Override
    public void deleteRoleById(Integer id) {
        scriptMapper.deleteRoleById(id);
    }

    @Override
    public void deleteSceneById(Integer id) {
        scriptMapper.deleteSceneById(id);
    }

    @Override
    public Role getRoleById(Integer id) {
        return scriptMapper.selectRoleById(id);
    }

    @Override
    public List<Role> getRolesByScriptId(Integer scriptId) {
        return scriptMapper.selectRolesByScriptId(scriptId);
    }

    @Override
    public Scene getSceneById(Integer id) {
        return scriptMapper.selectSceneById(id);
    }

    @Override
    public Scene getScenesByScriptId(Integer scriptId) {
        return scriptMapper.selectScenesByScriptId(scriptId);
    }

    @Override
    public void uploadImage(Integer id, String image) {
        scriptMapper.uploadScriptImage(id,image);
    }
}
